package com.woniuxy.kaer.service.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.jwtUtil.JwtUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.service.from.AddServiceRealDetailFrom;
import com.woniuxy.kaer.service.from.UpdateRealDetailFrom;
import com.woniuxy.kaer.service.param.AddServiceRealDetailParam;
import com.woniuxy.kaer.service.param.UpdateRealDetailParam;
import com.woniuxy.kaer.service.service.ServiceRealDetailService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程诗洋
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/serviceRealDetail")
@Api(tags = "订单消耗品接口")
public class ServiceRealDetailController {
    @Resource
    private ServiceRealDetailService serviceRealDetailService;
    @Resource
    private JwtUtil jwtUtil;
    //更改服务项目耗材
    //传数字
    @PutMapping("/updateServiceRealDetailByNumber")
    public Result updateServiceRealDetailByNumber(@RequestBody UpdateRealDetailFrom from)throws Exception{
        UpdateRealDetailParam updateRealDetailParam = BeanUtil.toBean(from, UpdateRealDetailParam.class);
        serviceRealDetailService.updateServiceRealDetail(updateRealDetailParam);
        return Result.succeed("通过更改数字更改服务项目耗材成功",null);
    }
    //+1
    @PutMapping("/realDetailByIncrease")
    public Result realDetailByIncrease(Integer serviceRealDetailId,@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        serviceRealDetailService.realDetailByIncrease(serviceRealDetailId,founderId);
        return Result.succeed("服务项目耗材+1",null);
    }
    //-1
    @PutMapping("/realDetailByAdd")
    public Result realDetailByDecrease(Integer serviceRealDetailId,@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        serviceRealDetailService.realDetailByDecreaseOne(serviceRealDetailId,founderId);
        return Result.succeed("服务项目耗材-1",null);
    }
    //删除
    @DeleteMapping("/deleteServiceRealDetail")
    public Result deleteServiceRealDetail(@RequestParam("serviceOrderId") String serviceOrderId,@RequestParam("serviceRealDetailId") Integer serviceRealDetailId,@RequestHeader("token") String token)throws Exception{
        Integer founderId = jwtUtil.getFounderId(token);
        serviceRealDetailService.deleteServiceRealDetail(serviceOrderId,serviceRealDetailId,founderId);
        return Result.succeed("删除服务项目耗材成功",null);
    }
    //新增服务耗材
    @PostMapping("/addServiceRealDetail")
    public Result addServiceRealDetail(@RequestBody AddServiceRealDetailFrom from,@RequestHeader("token") String token)throws Exception{
        AddServiceRealDetailParam addServiceRealDetailParam = BeanUtil.toBean(from, AddServiceRealDetailParam.class);
        Integer founderId = jwtUtil.getFounderId(token);
        addServiceRealDetailParam.setFounderId(founderId);
        serviceRealDetailService.addServiceRealDetail(addServiceRealDetailParam);
        return Result.succeed("新增服务项目耗材成功",null);
    }

}

